# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=graphviz
pkgname=haskell-graphviz
pkgver=2999.20.1.0
pkgrel=175
pkgdesc="Bindings to Graphviz for graph visualisation."
url="https://hackage.haskell.org/package/${_hkgname}"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-colour' 'haskell-dlist' 'haskell-fgl' 'haskell-polyparse'
         'haskell-temporary' 'haskell-wl-pprint-text')
makedepends=('ghc' 'uusi')
source=("$pkgname-$pkgver.tar.gz::https://github.com/ivan-m/graphviz/archive/$pkgver.tar.gz")
sha512sums=('9cd166f04565f9da56b93c6da49cc9f515a37762dd780e3868cf41c8d2b7709f627f0b60ecc31ce77249e38a53c74d1a989a9bfbf419f370cedf0c67526a9e7b')

prepare() {
    cd $_hkgname-$pkgver
    uusi -u fgl $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -f-test-parsing
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE.md "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.md
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE.md
}
